%{
	#include "parser.h"
	#include "LexVal.h"
	#include "main-tools.h"
	/*represents the lexical value that has just been read from the file*/
	LexVal lexval;
%}

%option header-file="lexer.h"
%option yylineno
%option noyywrap

delimiter				[ \n\t]
spacing					{delimiter}+
letter					[a-zA-Z]
digit					[0-9]
sign					(-|\+)
unsignedint				{digit}+
alphanum				({digit}|{letter})

comment_type1			\/\/[^\n]*
sugar					[{};,[\]():\.=><+\-*/%]
id						({letter}|_)({alphanum}|_)*

intconst				{unsignedint}
floatconst				{unsignedint}\.{unsignedint}
charconst				'(.|\n)'
stringconst				\"[^\n\"]*\"
boolconst				(true|false)

%x C_COMMENT

%%

{delimiter}				;


{comment_type1}			;
"/*"					{BEGIN(C_COMMENT);}
<C_COMMENT>(.|\n)		;
<C_COMMENT>"*/"			{BEGIN(INITIAL);}
					
{sugar}					{return yytext[0];}

require					{return TOKEN_REQUIRE;}
public					{return TOKEN_PUBLIC;}
package					{return TOKEN_PACKAGE;}
class					{return TOKEN_CLASS;}
static					{return TOKEN_STATIC;}
abstract				{return TOKEN_ABSTRACT;}
extends					{return TOKEN_EXTENDS;}
readable				{return TOKEN_READABLE;}
by						{return TOKEN_BY;}
writeable				{return TOKEN_WRITEABLE;}
all						{return TOKEN_ALL;}
onlyme					{return TOKEN_ONLYME;}
children				{return TOKEN_CHILDREN;}
member					{return TOKEN_MEMBER;}
of						{return TOKEN_OF;}
this					{return TOKEN_THIS;}
reference				{return TOKEN_REFERENCE;}
value					{return TOKEN_VALUE;}
array					{return TOKEN_ARRAY;}
-D						{return TOKEN_MINUS_D;}
int						{return TOKEN_INT;}
string					{return TOKEN_STRING;}
bool					{return TOKEN_BOOL;}
char					{return TOKEN_CHAR;}
const					{return TOKEN_CONST;}
var						{return TOKEN_VAR;}
function				{return TOKEN_FUNCTION;}
void					{return TOKEN_VOID;}
real					{return TOKEN_REAL;}
copy					{return TOKEN_COPY;}
while					{return TOKEN_WHILE;}
do						{return TOKEN_DO;}
for						{return TOKEN_FOR;}
to						{return TOKEN_TO;}
if						{return TOKEN_IF;}
then					{return TOKEN_THEN;}
elsif					{return TOKEN_ELSIF;}
else					{return TOKEN_ELSE;}
switch					{return TOKEN_SWITCH;}
case					{return TOKEN_CASE;}
default					{return TOKEN_DEFAULT;}
continue				{return TOKEN_CONTINUE;}
break					{return TOKEN_BREAK;}
return					{return TOKEN_RETURN;}
new						{return TOKEN_NEW;}

">="					{return TOKEN_GEQ;}
"<="					{return TOKEN_LEQ;}
==						{return TOKEN_EQ;}
!=						{return TOKEN_NE;}
"&&"					{return TOKEN_AND;}
"||"					{return TOKEN_OR;}


{intconst}				{lexval.ival=atoi(yytext);			 		return TOKEN_INTCONST;}
{stringconst}			{lexval.sval=initCString(yytext);			return TOKEN_STRINGCONST;}
{boolconst}				{lexval.ival=yytext[0]=='t'?1:0; 			return TOKEN_BOOLCONST;}
{floatconst}			{lexval.ival=atoi(yytext); 					return TOKEN_FLOATCONST;}
{charconst}				{lexval.ival=yytext[1]; 					return TOKEN_CHARCONST;}
	
{id}					{lexval.sval=initString(yytext); 	return TOKEN_ID;}

.						{lexval.sval=initString(yytext); 	return TOKEN_ERROR;}

%%